package com.fuhailiu.opengl.renders;

import android.content.Context;
import android.view.SurfaceHolder;

import com.fuhailiu.opengl.utils.LogUtil;
import com.fuhailiu.opengl.view.GLViewGroup;
import com.fuhailiu.opengl.widget.GLPointLine;

public class RenderPointLine extends AbsRender {

	private final String TAG = getClass().getSimpleName();

	private boolean mbStop;

	public RenderPointLine(Context context) {
		super(context);
	}

	@Override
	protected float[] getBackgroundColor() {
		return new float[] { 0, 0, 0, 1.0f };
	}

	@Override
	public void onSurfaceDestroyed(SurfaceHolder holder) {
		super.onSurfaceDestroyed(holder);
		mbStop = true;
	}

	@Override
	protected GLViewGroup makeWorld(Context context) {
		LogUtil.LogD(TAG, "makeWorld   <---");

		GLViewGroup layout = new GLViewGroup(context);

		final GLPointLine pointLine = new GLPointLine(context);
		layout.addView(pointLine);

		// change draw mode every 1s
		mbStop = false;
		new Thread(new Runnable() {
			@Override
			public void run() {
				while (!mbStop) {
					try {
						Thread.sleep(1000);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					pointLine.switchDrawMode();
				}
			}
		}).start();

		LogUtil.LogD(TAG, "makeWorld   --->");

		return layout;
	}
	
	@Override
	protected boolean useOrtho() {
		return false;
	}
}
